<!DOCTYPE html>
<html>
<head>
   <!-- 页面meta -->
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <title>传智健康</title>
   <meta name="description" content="传智健康">
   <meta name="keywords" content="传智健康">
   <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
   <!-- 引入样式 -->
   <link rel="stylesheet" href="../plugins/elementui/index.css">
   <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
   <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
   <div class="content-header">
      <h1>健康评估
         <small>风险测评</small>
      </h1>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
         <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
         <el-breadcrumb-item>健康评估</el-breadcrumb-item>
         <el-breadcrumb-item>风险测评</el-breadcrumb-item>
      </el-breadcrumb>
   </div>
   <div class="app-container">
      <div class="box">
         <!--搜索框-->
         <div class="filter-container">
            <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;"
                      class="filter-item"></el-input>
            <el-button @click="findPage()" class="dalfBut">查询</el-button>
         </div>
         <!--搜索框/-->

         <!--分页数据-->
         <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
            <el-table-column type="index" align="center" label="序号"  ></el-table-column>
            <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
            <el-table-column prop="name" label="姓名" align="center" ></el-table-column>
            <el-table-column prop="regTime" label="评估日期" align="center" ></el-table-column>

            <el-table-column prop="username" label="操作人" align="center" ></el-table-column>
            <el-table-column prop="status" label="报告状态" align="center" ></el-table-column>
            <el-table-column label="操作" align="center" min-width="150%">
               <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                  <el-button type="primary" size="mini" :disabled="scope.row.status == '未出报告'?true:false" @click="handleDownload(scope.row)">下载</el-button>
                  <!--scope.row代表当前行的对象-->
                  <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
               </template>
            </el-table-column>
         </el-table>
         <!--分页数据/-->

         <!--分页条-->
         <div class="pagination-container">
            <el-pagination
                    class="pagiantion"
                    @current-change="handleCurrentChange"
                    :current-page="pagination.currentPage"
                    :page-size="pagination.pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="pagination.total">
            </el-pagination>
         </div>
         <!--分页条/-->

         <!-- 编辑标签弹层 -->
         <div class="add-form">
            <el-dialog v-if="dialogFormVisible4Edit" title="编辑风险报告" :visible.sync="dialogFormVisible4Edit">
               <el-form ref="dataEditForm" :model="formData" label-position="right" label-width="100px">
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="会员编号">
                           <el-input :disabled="true" v-model="formData.id"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="档案号">
                           <el-input :disabled="true" v-model="formData.fileNumber"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="姓名">
                           <el-input :disabled="true" v-model="formData.name"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="评估时间">
                           <el-input :disabled="true" v-model="formData.regTime"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="操作人">
                           <el-input :disabled="true" v-model="formData.username"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="视力">
                           <el-input v-model="formData.vision"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="血压">
                           <el-input v-model="formData.blood"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="呼吸道">
                           <el-input v-model="formData.breathing"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="心脏">
                           <el-input v-model="formData.heard"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="体质">
                           <el-input v-model="formData.medecal"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="心理健康">
                           <el-input v-model="formData.psychology"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="心血管病">
                           <el-input v-model="formData.cardiovasc"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="结核病">
                           <el-input v-model="formData.tuberculosis"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="脑血管病">
                           <el-input v-model="formData.cerebral"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="糖尿病">
                           <el-input v-model="formData.diabetes"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="神经及精神疾病" label-width="110px">
                           <el-input v-model="formData.nerve"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="慢性疾病">
                           <el-input v-model="formData.disease"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
               </el-form>
               <div slot="footer" class="dialog-footer">
                  <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                  <el-button type="primary" @click="handleEdit()">确定</el-button>
               </div>
            </el-dialog>
         </div>
      </div>
   </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            showDialog: true, //弹框是否为新表单
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible4Edit: false,//编辑表单是否可见
        },

        //钩子函数，VUE对象初始化完成后自动执行,
        created() {
            //初始化分页查询
            this.findPage();
        },

        methods: {
            //编辑
            handleEdit() {
                //发送ajax请求
                axios.post("/risk/add.do",this.formData).then((res)=>{
                    //隐藏表单
                    this.dialogFormVisible4Edit = false;
                    if (res.data.flag) { //添加成功
                        //成功提示框
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    } else { //修改失败
                        //失败提示框
                        this.$message.error(res.data.message);
                    }
                }).finally(()=>{
                    //此处不能重置当前页：用户体验，修改后可以立马定位改的位置
                    //2.2分页查询
                    this.findPage(1); //不重置当前页
                });
            },

            //分页查询
            findPage(isCustom) {
                //debugger;
                //0.判断是从查询按钮调用此方法
                if (!isCustom) {//无惨:默认重置当前页
                    //将当前页码重置为1
                    this.pagination.currentPage = 1;
                }
                //console.log("hello findPage!");//测试
                //1.封装参数,当前页,每页尺寸,查询条件
                var para = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                //2.发送ajax请求
                axios.post("/risk/findPage.do", para).then(res => {
                    //获取返回结果{total:100,rows:[行数据]},赋值给分页模型
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;//赋值表数据

                }).finally();
            },

            // 重置表单
            resetForm() {
                //清除验证信息
                /*if (this.$refs['dataAddForm'] != undefined) {
                  this.$refs['dataAddForm'].resetFields();
                }*/
                //清除验证信息
                /*if (this.$refs['dataAddForm'] != undefined) {
                  this.$refs['dataAddForm'].clearValidate();
                }*/
                this.formData = {};
            },

            //下载报告
            handleDownload(row){
                window.location.href = '/risk/load4PDF/'+row.fileNumber+'.do';
                // //发送ajax请求，根据会员档案号查询数据
                // axios.post("/risk/load4PDF/"+row.fileNumber+".do").then((res) => {
                //     if (res.data.flag){
                //         this.$message({
                //            message:res.data.message,
                //            type:'success'
                //         });
                //     } else {
                //         this.$message.error(res.data.message);
                //     }
                // });
            },

            // 弹出编辑窗口
            handleUpdate(row) {
                //不使用row直接回显,可能其他管理员已经删除了此条数据,故以数据库为准
                //1.设置显示编辑窗口
                this.dialogFormVisible4Edit = true;

                //2.发送ajax,回显数据
                axios.get("/risk/getMember/" + row.fileNumber + ".do").then((res) => {
                    if (res.data.flag) {//查询成功
                        //设置回显数据
                        this.formData = res.data.data;
                    } else {//回显失败原因:多线程同时操作,页面数据已经不存在,故无法回显
                        this.$message.error(res.data.message);
                    }
                }).catch().finally();
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //当前页更改时回调函数
                //currentPage为新的当前页
                //1.修改当前页数据
                this.pagination.currentPage = currentPage;
                //2.调用分页查询方法
                this.findPage(1); //使用自定义当前页
            },

            // 删除
            handleDelete(row) {//row为当前行json对象

                //确认框
                this.$confirm('确认删除吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {//点确认,回调
                    //发送ajax请求
                    axios.delete("/risk/delete/" + row.fileNumber + ".do").then((res) => {
                        //判断是否删除成功
                        if (res.data.flag) {//删除成功
                            //成功框
                            app.$message({
                                message: res.data.message,
                                type: 'success'
                            });

                        } else {//删除失败
                            //失败框
                            this.$message.error(res.data.message);
                        }
                    }).finally(() => {//始终执行
                        this.findPage(1);//调用分页查询
                    });
                }).catch(() => {//点取消,回调
                    //取消框
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            }

        }
    });
</script>

</html>